package com.zh.note.huawei.onehundred.不等式or约束条件下的最大差;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/8/31 10:31
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // String line = sc.nextLine();
        String line = "2.3,3,5.6,7.6;11,3,8.6,25,1;0.3,9,5.3,66,7.8;1,3,2,7,5;340,670,80.6;<=,<=,<=";
        solution(line);

    }

    private static void solution(String line) {
        String[] split = line.split(";");
        double maxError = 0;
        // 不等式约束
        String[] limits = split[split.length - 1].split(",");
        //不等式目标值
        String[] aims = split[split.length - 2].split(",");
        //不等式变量
        String[] vars = split[split.length - 3].split(",");
        for (int i = 0; i < limits.length; i++) {
            // 获取系数
            String[] expression = split[i].split(",");
            // 把系数存到list
            List<Double> expressionList = new ArrayList<>();
            for (String s : expression) {
                expressionList.add(Double.parseDouble(s));
            }
            double value = calculateValue(expressionList, vars);
            double aim = Double.parseDouble(aims[i]);
            double error = Math.abs(value - aim);
            maxError = Math.max(error, maxError);
            if (!checkLimit(limits[i], value, aim)) {
                System.out.print("false ");
                System.out.println(new Double(maxError).intValue());
                return;
            }
        }
        System.out.print("true ");
        System.out.println(new Double(maxError).intValue());
    }

    //判断表达式
    private static boolean checkLimit(String limit, double value, double aim) {
        switch (limit) {
            case ">":
                return value > aim;
            case "<":
                return value < aim;
            case ">=":
                return value >= aim;
            case "<=":
                return value <= aim;
            default:
                return false;
        }
    }

    private static double calculateValue(List<Double> expressionList, String[] vars) {
        int res = 0;
        for (int i = 0; i < expressionList.size(); i++) {
            res += expressionList.get(i) * Integer.parseInt(vars[i]);
        }
        return res;

    }
}
